// page/cart/bless.js
var utils = require('../../utils/util.js');
var sliderWidth = 96; // 需要设置slider的宽度，用于计算中间位置

Page({
	data: {
		tabs: [],
		content: [],
		activeIndex: 0,
		sliderOffset: 0,
		sliderLeft: 0,


	},
	onLoad: function () {
		var that = this;
		utils.GET({
			url: 'Cart/bless',
			params: {},
			success: function (res) {
				that.setData({
					tabs: res.data.t,
					content: res.data.g,
				})
			},
		})

		wx.getSystemInfo({
			success: function (res) {
				that.setData({
					isHide: true,
					sliderLeft: (res.windowWidth / that.data.tabs.length - sliderWidth) / 2,
					sliderOffset: res.windowWidth / that.data.tabs.length * that.data.activeIndex
				});
			}
		});
	},
	tabClick: function (e) {
		this.setData({
			sliderOffset: e.currentTarget.offsetLeft,
			activeIndex: e.currentTarget.id
		});
	},
	textClick: function (e) {
		var detail = e.currentTarget.dataset.text
		var pages = getCurrentPages();
		var currPage = pages[pages.length - 1];   //当前页面
		var prevPage = pages[pages.length - 2];  //上个页面

		//直接调用上一个页面的setData()方法，把数据存到上一个页面中去
		prevPage.setData({
			heka: detail
		})
		wx.navigateBack({
			delta: 1
		})
	}
});